<template>
  <div class="base-content">
    <el-form label-width="100px"
             class="demo-ruleForm"
             label-position="top"
             :model="globaldata"
             :rules="rules"
             ref="globaldata">
      <div class="title">{{$t('configLazyLoad.visitorWaitConfig.wechatPush')}}</div>
      <el-form-item :label="$t('config.channel.AgentOfflineTipSet')" prop="weixinMsg">
        <el-input type="textarea" :rows="3" v-model="globaldata.weixinMsg"></el-input>
        <p class="remark">{{$t('configLazyLoad.visitorWaitConfig.wechatRemark1')}}</p>
      </el-form-item>
      <el-form-item :label="$t('config.channel.openPushTip')" prop="setWarnMsg">
        <el-radio-group v-model="globaldata.setWarnMsg">
          <el-radio class="radio" label="1" id="PushTipOn">{{$t('config.channel.enabled')}}</el-radio>
          <el-radio class="radio" label="0" id="PushTipOff">{{$t('config.channel.disabled')}}</el-radio>
        </el-radio-group>
        <p class="remark">{{$t('configLazyLoad.visitorWaitConfig.wechatRemark2')}}</p>
      </el-form-item>
      <el-form-item :label="$t('configLazyLoad.visitorWaitConfig.weixinWarnLen')" prop="weixinWarnLen" v-if="globaldata.setWarnMsg === '1'">
        <el-input v-model="globaldata.weixinWarnLen">
          <template slot="append">{{$t('public.minutes2')}}</template>
        </el-input>
        <span class="remark">{{$t('configLazyLoad.visitorWaitConfig.default10Min')}}</span>
      </el-form-item>
      <el-form-item :label="$t('configLazyLoad.visitorWaitConfig.wechatRemark8')" prop="weixinWarnMsg" v-if="globaldata.setWarnMsg === '1'">
        <el-input type="textarea" :placeholder="$t('configLazyLoad.visitorWaitConfig.wechatRemark7')" v-model="globaldata.weixinWarnMsg"></el-input>
      </el-form-item>
      <div class="title">{{$t('configLazyLoad.visitorWaitConfig.wechatRemark6')}}</div>
      <el-form-item :label="$t('config.channel.wechatQueueTipSet')" prop="weixinQueueNumSwitch">
        <el-input type="textarea" :rows="3" :placeholder="$t('configLazyLoad.visitorWaitConfig.wechatRemark5')" v-model="globaldata.weixinQueueNumSwitch"></el-input>
        <p class="remark">{{$t('configLazyLoad.visitorWaitConfig.wechatRemark4')}}</p>
        <p class="remark remarkImport">{{$t('configLazyLoad.visitorWaitConfig.wechatRemark3')}}</p>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" class="primary_btn fr" v-on:click="SaveSet">{{$t('public.save')}}</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
  import {checkform} from '@/utils/validate'
  export default {
    name: 'wechatClientSet',
    data () {
      let validateNum = (rule, value, callback) => {
        let message = checkform(value, 'Number3')
        if (message) {
          callback(new Error(this.$t(message)))
        } else {
          callback()
        }
      }
      return {
        globaldata: {
          _id: '',
          weixinMsg: '',
          setWarnMsg: '1',
          weixinWarnLen: '10',
          weixinWarnMsg: '',
          weixinQueueNumSwitch: ''
        },
        rules: {
          weixinWarnLen: [
            {required: true, message: this.$t('validate.required'), trigger: 'blur'},
            {validator: validateNum, trigger: 'blur'}
          ]
        }
      }
    },
    methods: {
      SaveSet () {
        this.$refs.globaldata.validate((valid) => {
          if (valid) {
            if (this.globaldata.setWarnMsg === '1' && this.globaldata.weixinWarnLen === '') {
              this.$message.error(this.$t('configLazyLoad.visitorWaitConfig.weixinWarnLenMust'))
              return
            }
            this.$store.dispatch('saveGlobalSet', this.globaldata).then((rep) => {
              if (rep.success) {
                this.$message.success(this.$t('config.channel.configSuccess'))
              } else {
                this.$message.error(this.$t('qualityCheck.saveFali'))
              }
            })
          }
        })
      }
    },
    mounted () {
      this.$store.dispatch('getGlobalSetById', {}).then((resp) => {
        if (resp.success && resp.row) {
          this.globaldata._id = resp.row._id
          this.globaldata.weixinMsg = resp.row.weixinMsg || ''
          this.globaldata.setWarnMsg = resp.row.setWarnMsg || '1'
          this.globaldata.weixinWarnLen = resp.row.weixinWarnLen || '10'
          this.globaldata.weixinWarnMsg = resp.row.weixinWarnMsg || ''
          this.globaldata.weixinQueueNumSwitch = resp.row.weixinQueueNumSwitch || ''
        }
      })
    }
  }
</script>
<style lang="stylus" scoped>
  .base-content
    /*height: calc(100vh - 200px);*/
    /*overflow-y: auto;*/
    /*padding: 10px 20px*/
    .first-row
      margin:20px 0 5px 0
    .labels
      margin-top 5px
    .remark
      color: #888888
      font-size 12px
    .remarkImport
      color: #3b5998
    .right
      text-align right
  .el-form
    width 500px
    .el-form-item
      margin-bottom 20px
      .el-input
        color $cf-level3
      p
        font-size 12px
        color $cf-level3
  .title
    font-weight: 900
    font-size: 14px
    margin-bottom: 5px
</style>




















